#pragma once

#include <iostream>
#include <vector>
#include <string>
#include <unistd.h>
#include <unordered_map>
#include <functional>

typedef std::function<void()> func;

std::vector<func> callbacks;
std::unordered_map<int, std::string> desc;

void readMySQL()
{
    std::cout << "sub process [" << getpid() << "] 执行数据库访问任务\n" << std::endl;
}

void executeUrl()
{
    std::cout << "sub process [" << getpid() << "] 执行解析Url任务\n" << std::endl;
}

void cal()
{
    std::cout << "sub process [" << getpid() << "] 执行加密任务\n" << std::endl;
}

void save()
{
    std::cout << "sub process [" << getpid() << "] 执行数据存储任务\n" << std::endl;
}

void load()
{
    desc.insert({ callbacks.size(), "readMySQL: 读取数据库" });
    callbacks.push_back(readMySQL);

    desc.insert({ callbacks.size(), "executeUrl: 进行Url解析" });
    callbacks.push_back(executeUrl);

    desc.insert({ callbacks.size(), "cal: 进行加密计算" });
    callbacks.push_back(cal);

    desc.insert({ callbacks.size(), "save: 进行数据的保存" });
    callbacks.push_back(save);
}

void showHandler()
{
    for (const auto &iter : desc)
    {
        std::cout << iter.first << "\t" << iter.second << std::endl;
    }
}

int handlerSize()
{
    return callbacks.size();
}